package com.chen.dataupload.controller;

import com.chen.dataupload.entity.Student;
import com.chen.dataupload.mapper.StudentMapper;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
public class HelloController {

    @Autowired
    private StudentMapper studentMapper;


    @RequestMapping("/getData")
    public String reviceData(@RequestParam String data) throws Exception{
        ObjectMapper mapper = new ObjectMapper();
        JavaType jt = mapper.getTypeFactory().constructParametricType(ArrayList.class, Student.class);
        List<Student> list = mapper.readValue(data,jt);
        for (int i = 0; i < list.size(); i++) {
            studentMapper.insert(list.get(i));
        }
        return "hello";
    }
}
